package statistics;

import impsoft.utils.general.Timer;

import java.math.BigDecimal;

import base.DreamScript;
import base.DreamUtility;

public class Formatter extends DreamUtility {

	public Formatter(DreamScript cs) {
		super(cs);
	}

	public double round(double d, int decimalPlace) {
		return new BigDecimal(Double.toString(d)).setScale(decimalPlace, BigDecimal.ROUND_HALF_UP).doubleValue();
	}

	public String getHourlyValueFormatted(long value, Timer timeRan) {
		return formatValue(value * 60 * 60 / (timeRan.getTimeElapsed() / 1000 + 1));
	}

	public long getHourlyValue(long value, Timer timeRan) {
		return value * 60 * 60 / (timeRan.getTimeElapsed() / 1000 + 1);
	}

	public String formatValue(long value) {
		String format = "0";

		if (value < 1000) {
			format = "" + value;
		} else if (value > 1000 && value < 1000000) {
			format = round(value / 1000, 2) + "k";
		} else if (value > 1000000 && value < 1000000000) {
			format = round(value / 1000000, 2) + "M";
		} else if (value > 1000000000) {
			format = round(value / 1000000000, 2) + "B";
		}

		return format;
	}

	public String formatValue(double value) {
		String format = "0.00";

		if (value < 1000) {
			format = "" + value;
		} else if (value > 1000 && value < 1000000) {
			format = round(value / 1000, 2) + "k";
		} else if (value > 1000000 && value < 1000000000) {
			format = round(value / 1000000, 2) + "M";
		} else if (value > 1000000000) {
			format = round(value / 1000000000, 2) + "B";
		}

		return format;
	}
}
